package com.yanqu.road.entity.activity.args;

import com.yanqu.road.entity.activity.fellingtrees.FellingTreesEquip;
import com.yanqu.road.entity.activity.fellingtrees.FellingTreesUserData;
import com.yanqu.road.entity.activity.fellingtrees.config.FellingTreesConfig;

public class FellingTreesLevelArgs {

    /**
     * 等级
     */
    private int level;

    /**
     * 参数，格式：法力值#唯一id;装备id;等级;基础等级|唯一id;装备id;等级;基础等级|......
     */
    private String equipData;

    private FellingTreesLevelArgs() {
        // 用create方法生成
    }

    public static FellingTreesLevelArgs create(FellingTreesConfig config, FellingTreesUserData userData) {
        FellingTreesLevelArgs args = new FellingTreesLevelArgs();
        args.setLevel(userData.getTopLevel());

        StringBuilder sb = new StringBuilder();
        sb.append(userData.getAttack().toString());
        sb.append("#");
        for (long uid : userData.getEquipPosArr()) {
            FellingTreesEquip equip = userData.getEquipMap().get(uid);
            sb.append(uid);
            sb.append(";");
            sb.append(equip == null ? 0 : equip.getEquipId());
            sb.append(";");
            if (equip != null && config.isDaoqi(equip.getEquipId())) {
                //为道器时,该字段值为道器星级
                int star = config.getDaoqiStar(equip);
                sb.append(star);
            } else {
                sb.append(equip == null ? 0 : equip.getLv());
            }
            sb.append(";");
            sb.append(equip == null ? 0 : equip.getBaseLv());
            sb.append("|");
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
        }

        args.setEquipData(sb.toString());
        return args;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getEquipData() {
        return equipData;
    }

    public void setEquipData(String equipData) {
        this.equipData = equipData;
    }

}
